package com.yiwei.zxp.activity;

import android.os.Bundle;
import android.text.Spanned;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.api.Api;
import com.yiwei.zxp.api.bean.WithdrawDetailBean;
import com.yiwei.zxp.api.model.WithdrawDetailModel;
import com.yiwei.zxp.base.BaseActivity;
import com.yiwei.zxp.util.Network;
import com.yiwei.zxp.util.RxLifeUtil;
import com.yiwei.zxp.util.Spans;
import com.yiwei.zxp.util.ToastUtil;
import com.yiwei.zxp.view.V19FrameLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by xsooy-pc on 17-12-8.
 */

public class WithdrawDetailActivity extends BaseActivity {
    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_right)
    TextView txtRight;
    @BindView(R.id.layout_title)
    V19FrameLayout layoutTitle;
    @BindView(R.id.txt_status)
    TextView txtStatus;
    @BindView(R.id.txt_left_content)
    TextView txtLeftContent;
    @BindView(R.id.txt_right_content)
    TextView txtRightContent;

    private Unbinder unbiner;
    private int x26;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_withdraw_detail);
        initBar();
        unbiner = ButterKnife.bind(this);
        init();
    }

    private void init() {
        txtTitle.setText("提现详情");
        x26 = getResources().getDimensionPixelSize(R.dimen.x26);
        String order_no = getIntent().getStringExtra("order_no");
        getWithdrawDetail(order_no);
    }

    public void getWithdrawDetail(String order_no) {
        if (!Network.checkNetwork(this)) {
            ToastUtil.show(this, "网络连接失败");
            return;
        }

        loadingDialog.show();
        WithdrawDetailBean bean = new WithdrawDetailBean();
        bean.order_no = order_no;
        Api.api_service.getWithdrawDetail(bean).compose(RxLifeUtil.checkOn(this)).
                doFinally(() -> {
                    try {
                        loadingDialog.dismiss();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    setWithdrawDetail(result.datas);
                });
    }

    private void setWithdrawDetail(WithdrawDetailModel.DatasBean item) {
        Spanned txt_left = Spans.with(this).font("提现账户", x26, 0xff999999).
                font("\n到账银行", x26, 0xff999999).
                font("\n提现金额", x26, 0xff999999).
                font("\n提现手续费", x26, 0xff999999).
                font("\n实际到账金额", x26, 0xff999999).
                build();
        txtLeftContent.setText(txt_left);

        Spanned txt_right = Spans.with(this).font(item.bankCard, x26, 0xff333333).
                font("\n" + item.bankName, x26, 0xff333333).
                font("\n" + item.money + "元", x26, 0xff333333).
                font("\n" + item.rate, x26, 0xff333333).
                font("\n" + item.true_money + "元", x26, 0xff333333).
                build();
        txtRightContent.setText(txt_right);
        if (item.status.equals("0")) {
            txtStatus.setText("审核中");
        } else if (item.status.equals("1")) {
            txtStatus.setText("已完成");
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbiner.unbind();
        unbiner = null;
    }

    @OnClick(R.id.btn_back)
    public void onViewClicked() {
        finish();
    }
}
